package com.woniuxy.Controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.RbacRole;
import com.woniuxy.entity.RbacRoleDto;
import com.woniuxy.service.RbacRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * (RbacRole)表控制层
 *
 * @author makejava
 * @since 2021-04-25 23:04:56
 */
@RestController
@RequestMapping("rbacRole")
public class RbacRoleController {
    /**
     * 服务对象
     */
    @Resource
    private RbacRoleService rbacRoleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public RbacRole selectOne(Integer id) {
        return this.rbacRoleService.queryById(id);
    }
    /**
     * Description : 为列表提供  <br/>
     * ChangeLog : 1. 创建 (2021/4/27 22:12 [mayuhang]);
     * @param startpage
     * @param pagesize
     * @return com.github.pagehelper.PageInfo<com.woniuxy.entity.RbacRole>
     **/
    @GetMapping("selectAll")
    public PageInfo<RbacRole> selectOne(int startpage,int pagesize) {
        PageHelper.startPage(startpage,pagesize);
        Page<RbacRole> page = (Page<RbacRole>) this.rbacRoleService.queryAllByLimit();
        PageInfo<RbacRole> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }
    /**
     * Description : 为下拉框提供提供  <br/>
     * ChangeLog : 1. 创建 (2021/4/27 22:12 [mayuhang]);
     * @return com.github.pagehelper.PageInfo<com.woniuxy.entity.RbacRole>
     **/
    @GetMapping("selectChoiseAll")
    public List<RbacRole> selectAllN() {
        List<RbacRole> rbacRoles = this.rbacRoleService.queryAllByLimit();
        return rbacRoles;
    }
    /**
     * Description : 为列表提供  <br/>
     * ChangeLog : 1. 创建 (2021/4/27 22:12 [mayuhang]);
     * @return com.github.pagehelper.PageInfo<com.woniuxy.entity.RbacRole>
     **/
    @GetMapping("selectAllNoPage")
    public List<RbacRole> selectOne() {
        List<RbacRole> rbacRoles = this.rbacRoleService.queryAllByLimit();
        return rbacRoles;
    }

    @RequestMapping("addRole")
    public String addPerm(@RequestBody RbacRole RbacRole){
        this.rbacRoleService.insert(RbacRole);
        return "success";
    }

    @RequestMapping("deleteRole/{id}")
    public String deletePerm(@PathVariable("id") int id){
        this.rbacRoleService.deleteById(id);
        return "success";
    }
    @RequestMapping("updateRole")
    public String updatePerm(@RequestBody RbacRole RbacRole){
        this.rbacRoleService.update(RbacRole);
        return "success";
    }
    @RequestMapping("search")
    public PageInfo<RbacRole> search(@RequestBody RbacRoleDto RbacRoleDto){
        System.out.println(RbacRoleDto.toString());
        PageHelper.startPage(RbacRoleDto.getPage(),RbacRoleDto.getLimit());
        List<RbacRole> search = this.rbacRoleService.search(RbacRoleDto.getRbacRole());
        Page<RbacRole> page = (Page) search;
        PageInfo<RbacRole> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @RequestMapping("findPerms")
    public List<RbacRole> findAllPerm(){
        return this.rbacRoleService.findPerms();
    }
    /**
     * Description : 通过角色查菜单(权限)  <br/>
     * ChangeLog : 1. 创建 (2021/4/29 9:57 [mayuhang]);
     * @return null
     **/
    @RequestMapping("selectMenuAll")
    public List<RbacRole> findManyMenu(){
    return this.rbacRoleService.selectMenuAll();
    }
}
